import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 101,
    list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  },
  getters: {
    filterList (state) {
      return state.list.filter(item => item > 5)
    }
  },
  mutations: {
    addCount (state, n) {
      state.count += n
    },
    subCount (state, n) {
      state.count -= n
    },
    resetCount (state, newCount) {
      state.count = newCount
    }
  },
  actions: {
    setAsyncCount (context, n) {
      setTimeout(() => {
        context.commit('resetCount', n)
      }, 1000)
    }
  },
  modules: {
  }
})
